package com.zg.common.core.util;

import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * @author Zxb
 */
public class DesUtil {
    /**
     * key需要24位
     */
    public static String encrypt(String str, String key) {
        SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DES, key.getBytes());
        return des.encryptHex(str);
    }

    public static String decrypt(String str, String key) {
        SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DES, key.getBytes());
        return des.decryptStr(str);
    }

    public static void main(String[] args) {
        String str = "张晓波Zxb01231";
        String key = "sgEsnN6QWq8W7j5Hgxvwq4lo";
        String result = encrypt(str, key);
        System.out.println("加密后：" + result);
        String text = decrypt(result, key);
        System.out.println("解密后：" + text);
    }
}
